export const options = {
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    credentials: 'include',
    method: 'POST'
}

export const handleResponse = (response) => {
    if (!response.ok) {
        handleError(response.json());
    } else {
        return response.text();
    }
}

export const handleError = (handledError) => {
    handledError.then(err => {
        switch (err.status) {
            case 500:
                if (err.message.includes("@")) {
                    toastr.warning(err.message.replace("@", ""))
                } else {
                    toastr.warning('系统繁忙，请稍后再试')
                    // console.log("err 500", err)
                    throw err
                }
                break;
            case 403:
                location.hash = "#/login"
                break;
            default:
                toastr.warning('系统繁忙，请稍后再试')
                // console.log("err", err)
                throw err
                break;
        }
    })
}
